home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
TeX 1995 July
/
TeX CD-ROM July 1995 (Disc 1)(Walnut Creek)(1995).ISO
/
macros
/
latex209
/
contrib
/
geom
/
mathlabels.orig
< prev
next >
Wrap
Text File
|
1993-01-11
|
3KB
|
136 lines
#!/usr/local/bin/perl
#
# This is mathlabels, Copyright 1992 Silvio Levy
# $Header: /a/tampa/h/tampa_a/fac/levy/texts/geombook/RCS/mathlabels,v 1.1 92/07/17 13:27:40 levy Exp $
#
#
# first argument: file name for labels
# second to fifth arguments: xlo, xhi, ylo, yhi (to fix the aspect ratio)
# use OK for these arguments if no changes need to be made
#
die "$0 expects 5 arguments\n"
if ($#ARGV != 4);
$filename=$ARGV[0]; shift;
$xlo=$ARGV[0]; shift;
$xhi=$ARGV[0]; shift;
$ylo=$ARGV[0]; shift;
$yhi=$ARGV[0]; shift;
die "Can't open $filename" unless open(labels,">$filename");
#
# get various parameters output by psfix
#
while (<>) {
print;
last if (/MathPictureStart/);
($trash,$lmarg)=split(' ') if (/\/Mlmarg/);
($trash,$rmarg)=split(' ') if (/\/Mrmarg/);
($trash,$bmarg)=split(' ') if (/\/Mbmarg/);
($trash,$tmarg)=split(' ') if (/\/Mtmarg/);
($trash,$width)=split(' '), $width*=72 if (/\/Mwidth/);
($trash,$height)=split(' '), $height*=72 if (/\/Mheight/);
($trash,$nodistort)=split(' ') if (/\/Mnodistort/);
}
&doit(0,0,$width,$height);
sub doit {
local($XLO,$YLO,$XHI,$YHI)=@_; # target bounding box
local($Ax,$Bx,$Ay,$By);
line:
while (<>) {
return if (/^MathSubEnd/);
if (/ MathSubStart/) {
($Xlo,$Ylo,$Xhi,$Yhi) = split(' ');
print;
&doit($Xlo*$Ax+$Bx,$Ylo*$Ay+$By,$Xhi*$Ax+$Bx,$Yhi*$Ay+$By);
}
#
# look between the lines
#
# % Scaling calculations
# ... [
# ] MathScale
#
# to mimic the action of MathScale
#
if (/% Scaling calculations/) {
$collecting=1;
$npts=-2;
}
if ($collecting) { #[
if (/] MathScale/) {
#
# do the calculations
#
$collecting=0;
$i=0;
while ($i<$npts-2) {
print($point[$npts]);
}
($trash,$gxlow,$gylow) = split(' ',$point[$npts-2]);
$gxlow=$xlo unless ($xlo=~/OK/);
$gylow=$ylo unless ($ylo=~/OK/);
print("[ $gxlow $gylow 0 0 ]\n");
($trash,$gxhigh,$gyhigh) = split(' ',$point[$npts-1]);
$gxhigh=$xhi unless ($xhi=~/OK/);
$gyhigh=$yhi unless ($yhi=~/OK/);
print("[ $gxhigh $gyhigh 0 0 ]\n");
($Ax,$Ay,$Bx,$By) =
&findpars($XLO,$YLO,$XHI,$YHI,$gxlow,$gylow,$gxhigh,$gyhigh);
print;
} else {
#
# put scaling lines into an array
#
if ($npts>=0) {
if (!/Msboxa/) {
$point[$npts] = $_;
$npts++;
}
} else {
print;
$npts++;
}
}
next line;
}
#
# issue labeling command
#
if (/\[\((.*)\)\] *([^ ]*) *([^ ]*) *([^ ]*) *([^ ]*) *Mshowa/) {
$_=$1;
$xpos=$2*$Ax+$Bx;
$ypos=$3*$Ay+$By;
$xrelpos=$4;
$yrelpos=$5;
s/\\([\\()])/$1/g;
printf labels ("\\setlabel{%s}{%f}{%f}{%f}{%f}\n",
$_,$xpos,$ypos,$xrelpos,$yrelpos);
next line;
}
print;
}
}
sub findpars {
local($xlow,$ylow,$xhigh,$yhigh,$gxlow,$gylow,$gxhigh,$gyhigh)=@_;
local ($Ax,$Ay,$Bx,$By);
$Ax=($xhigh-$xlow)/($gxhigh-$gxlow);
$Ay=($yhigh-$ylow)/($gyhigh-$gylow);
if ($nodistort=~/true/) {
$Ax=$Ay if ($Ax>$Ay);
$Ay=$Ax if ($Ay>$Ax);
}
$Bx=(($xlow+$xhigh)-($gxlow+$gxhigh)*$Ax)/2;
$By=(($ylow+$yhigh)-($gylow+$gyhigh)*$Ay)/2;
return($Ax,$Ay,$Bx,$By);
}